package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.api.FeignPaymentClient;
import com.atguigu.springcloud.entities.CommonResult;
import com.atguigu.springcloud.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController  
@Slf4j  
public class OrderController {

    // 自动装配 Feign 接口
    @Autowired
    private FeignPaymentClient feignPaymentClient;

    @PostMapping("/consumer/payment/create")
    public CommonResult<Integer> create(Payment payment){
        // 像调用本地方法一样调用远程方法
        return feignPaymentClient.create(payment);
    }
  
    @GetMapping("/consumer/payment/get/{id}")  
    public CommonResult<Payment> getPayment(@PathVariable("id") Long id){  
        return feignPaymentClient.getPaymentById(id);
    }
}